home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / URIFileScheme.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  4.7 KB  |  197 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.plugin.PluginRegistry;
  4. import com.extensibility.plugin.api.URIScheme;
  5. import com.extensibility.plugin.api.URISchemeAdapter;
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.FileOutputStream;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.io.OutputStream;
  14. import java.io.Reader;
  15. import java.io.Writer;
  16. import java.util.Vector;
  17.  
  18. public class URIFileScheme extends URISchemeAdapter {
  19.    private File file;
  20.  
  21.    public static void registerPlugin(PluginRegistry var0) {
  22.       var0.registerPlugin("URIScheme10", Class.forName("com.extensibility.xml.URIFileScheme"), "URIFileScheme", 65537);
  23.    }
  24.  
  25.    public URIFileScheme() {
  26.       this.file = null;
  27.    }
  28.  
  29.    public URIFileScheme(File var1) {
  30.       this.file = var1;
  31.    }
  32.  
  33.    public void registerSchemes(URIScheme.Manager var1) {
  34.       var1.registerScheme("file", Class.forName("java.io.File"), this);
  35.    }
  36.  
  37.    public URIScheme construct(String var1, String var2) {
  38.       if (var2.startsWith("file://")) {
  39.          var2 = var2.substring(7);
  40.       } else {
  41.          var2 = var2.substring(5);
  42.       }
  43.  
  44.       var2 = var2.replace('/', File.separatorChar);
  45.       return new URIFileScheme(new File(var2));
  46.    }
  47.  
  48.    public URIScheme construct(Object var1) {
  49.       return new URIFileScheme((File)var1);
  50.    }
  51.  
  52.    public URIScheme construct(String var1) {
  53.       var1 = var1.replace('/', File.separatorChar);
  54.       File var2 = new File(this.file.getParent(), var1);
  55.       return new URIFileScheme(var2);
  56.    }
  57.  
  58.    public static Vector getFileParents(File var0) {
  59.       Vector var1 = new Vector();
  60.  
  61.       String var2;
  62.       while((var2 = var0.getParent()) != null) {
  63.          var0 = new File(var2);
  64.          var1.insertElementAt(var0, 0);
  65.       }
  66.  
  67.       return var1;
  68.    }
  69.  
  70.    public String computeRelative(URIScheme var1) {
  71.       URIFileScheme var2 = (URIFileScheme)var1;
  72.       File var3 = var2.file;
  73.       Vector var4 = getFileParents(var2.file);
  74.       Vector var5 = getFileParents(this.file);
  75.       int var7 = 0;
  76.       boolean var8 = true;
  77.  
  78.       while(var7 < var5.size() && var7 < var4.size() && var8) {
  79.          File var6 = (File)var5.elementAt(var7);
  80.          File var9 = (File)var4.elementAt(var7);
  81.          var8 = var6.equals(var9);
  82.          if (var8) {
  83.             ++var7;
  84.          }
  85.       }
  86.  
  87.       StringBuffer var12 = new StringBuffer();
  88.       if (var7 > 0) {
  89.          int var10;
  90.          for(var10 = var7; var7 < var4.size(); ++var7) {
  91.             var12.append("../");
  92.          }
  93.  
  94.          while(var10 < var5.size()) {
  95.             File var11 = (File)var5.elementAt(var10);
  96.             var12.append(var11.getName());
  97.             var12.append('/');
  98.             ++var10;
  99.          }
  100.  
  101.          var12.append(this.file.getName());
  102.       } else {
  103.          var12.append(this.file.getAbsolutePath().replace(File.separatorChar, '/'));
  104.          if (var12.charAt(0) != '/') {
  105.             var12.insert(0, '/');
  106.          }
  107.       }
  108.  
  109.       return var12.toString();
  110.    }
  111.  
  112.    public URIScheme toParent() {
  113.       URIFileScheme var1 = null;
  114.       String var2 = this.file.getParent();
  115.       if (var2 != null) {
  116.          var1 = new URIFileScheme(new File(var2));
  117.       }
  118.  
  119.       return var1;
  120.    }
  121.  
  122.    public String getScheme() {
  123.       return "file";
  124.    }
  125.  
  126.    public URIScheme renameTo(String var1) {
  127.       File var2 = new File(this.file.getParent(), var1);
  128.       URIFileScheme var3 = null;
  129.       if (this.file.renameTo(var2)) {
  130.          var3 = new URIFileScheme(var2);
  131.       }
  132.  
  133.       return var3;
  134.    }
  135.  
  136.    public long getLength() {
  137.       return this.file.length();
  138.    }
  139.  
  140.    public InputStream createInputStream() throws IOException {
  141.       return new FileInputStream(this.file);
  142.    }
  143.  
  144.    public Reader createReader() throws IOException {
  145.       return new FileReader(this.file);
  146.    }
  147.  
  148.    public Writer createWriter() throws IOException {
  149.       return new FileWriter(this.file);
  150.    }
  151.  
  152.    public OutputStream createOutputStream() throws IOException {
  153.       return new FileOutputStream(this.file);
  154.    }
  155.  
  156.    public boolean exists() {
  157.       return this.file != null && this.file.exists() && !this.file.isDirectory();
  158.    }
  159.  
  160.    public boolean isReadOnly() {
  161.       boolean var1;
  162.       if (!this.file.exists()) {
  163.          var1 = false;
  164.       } else {
  165.          var1 = !this.file.canWrite();
  166.       }
  167.  
  168.       return var1;
  169.    }
  170.  
  171.    public boolean equals(URIScheme var1) {
  172.       URIFileScheme var2 = (URIFileScheme)var1;
  173.       return this.file.equals(var2.file);
  174.    }
  175.  
  176.    public int compareTo(URIScheme var1) {
  177.       URIFileScheme var2 = (URIFileScheme)var1;
  178.       return this.file.getAbsolutePath().compareTo(var2.file.getAbsolutePath());
  179.    }
  180.  
  181.    public String getShortName() {
  182.       return this.file.getName();
  183.    }
  184.  
  185.    public String getFullPath() {
  186.       String var1 = this.file.getAbsolutePath();
  187.       String var2 = var1.replace(File.separatorChar, '/');
  188.       StringBuffer var3 = new StringBuffer("file://");
  189.       if (!var2.startsWith("/")) {
  190.          var3.append("/");
  191.       }
  192.  
  193.       var3.append(var2);
  194.       return var3.toString();
  195.    }
  196. }
  197.